<?php
namespace app\appin\middleware;

use app\common\model\Lang;
use think\facade\Session;

class Appin
{
    protected $session;

    public function __construct(\think\Session $session)
    {
        $this->session = $session;
    }

	/**
	 * @param $request
	 * @param \Closure $next
	 */
	public function handle($request, \Closure $next)
	{
	    $lang       = $request->param('lang', 'zh-cn', 'strip_tags');
        $lang_id    = Lang::where('tag', $lang)->value('id');
        $this->session->set('lang.id', $lang_id);
        $this->session->set('lang.tag', $lang);
		return $next($request);
	}
}
